package com.woniu.microuserserver.service.impl;

import com.github.pagehelper.ISelect;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.microcommonsserver.entity.RoleInfoEntity;
import com.woniu.microcommonsserver.entity.RolePermEntity;
import com.woniu.microcommonsserver.entity.UserInfoEntity;
import com.woniu.microuserserver.bean.RoleQuery;
import com.woniu.microuserserver.mapper.RoleMapper;
import com.woniu.microuserserver.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoleServiceimpl implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    @Override
    public PageInfo<RoleInfoEntity> searchByQuery(RoleQuery roleQuery) {
        PageInfo<RoleInfoEntity> pageInfo = PageHelper.startPage(roleQuery.getPageNum(), roleQuery.getPageSize()).doSelectPageInfo(new ISelect() {
            @Override
            public void doSelect() {
                roleMapper.searchByQuery(roleQuery);
            }
        });
        return pageInfo;
    }

    @Override
    public int updateRole(RoleInfoEntity roleInfoEntity) {
        return roleMapper.updateRole(roleInfoEntity);
    }

    @Override
    public int addRole(RoleInfoEntity roleInfoEntity) {
        return roleMapper.addRole(roleInfoEntity);
    }

    @Override
    public int checkUidByrid(int rid) {
        return roleMapper.checkUidByrid(rid);
    }

    @Override
    public int delRole(int rid) {
        return roleMapper.delRole(rid);
    }

    @Override
    public int updateRoleStatus(RoleInfoEntity roleInfoEntity) {
        return roleMapper.updateRoleStatus(roleInfoEntity);
    }

    @Override
    public int addUserToRole(int rid, int uid) {
        return roleMapper.addUserToRole(rid,uid);
    }

    @Override
    public List<Integer> findTheRoleHasUser(int rid) {
        return roleMapper.findTheRoleHasUser(rid);
    }

    @Override
    public int removeUserFromRole(int rid) {
        return roleMapper.removeUserFromRole(rid);
    }

    @Override
    public int addPermToRole(int rid, int hp, int wp, int bp, int up) {
        return roleMapper.addPermToRole(rid,hp,wp,bp,up);
    }

    @Override
    public int delPermByRid(int rid) {
        return roleMapper.delPermByRid(rid);
    }

    @Override
    public RolePermEntity getPermsByRid(int rid) {
        return roleMapper.getPermsByRid(rid);
    }
}
